package cn.itcast.service.impl;

import cn.itcast.dao.SignRepository;
import cn.itcast.dao.TransitRepository;
import cn.itcast.domain.transit.SignInfo;
import cn.itcast.domain.transit.TransitInfo;
import cn.itcast.index.WayBillIndexRepository;
import cn.itcast.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SignServiceImpl implements SignService {
    @Autowired
    private SignRepository signRepository;
    @Autowired
    private TransitRepository transitRepository;
    @Autowired
    private WayBillIndexRepository wayBillIndexRepository;
    @Override
    @Transactional
    public void save(String transitInfoId, SignInfo signInfo) {
        signRepository.save(signInfo);
        TransitInfo transitinfo = transitRepository.findOne(Integer.parseInt(transitInfoId));
        transitinfo.setSignInfo(signInfo);
        if (signInfo.getSignType().equals("正常")){
              transitinfo.setStatus("正常签收");
              transitinfo.getWayBill().setSignStatus(3);
        }else {
            //异常
            transitinfo.setStatus("异常");
            transitinfo.getWayBill().setSignStatus(4);
        }
        //同步更新数据到索引库
        wayBillIndexRepository.save(transitinfo.getWayBill());
    }
}
